<script setup>
import { useRouter } from "vue-router";
import myAxios from "../plugins/myAxios.js";
import { ref, onMounted } from "vue";
import { getCurrentUser, exit } from '../services/user.js'
const router = useRouter();
const user = ref({});
// onMounted钩子函数，发请求获取User信息
onMounted(async () => {
    user.value = await getCurrentUser();
});

// // mockUser数据
// const user = {
//     id: 1,
//     username: "lishui",
//     userAccount: "2419773293",
//     avatarUrl: "../../public/头像.jpg",
//     gender: "男",
//     phone: "17623373439",
//     email: "2419773293@qq.com",
//     planetCode: "kenn",
//     createTime: new Date(),
// };
// 跳转到编辑页
const toEdit = (editKey, editName, currentValue) => {
    router.push({
        path: "/inter/user/edit",
        query: {
            editKey,
            editName,
            currentValue,
            userId: user.value.id,
        },
    });
};
</script>
<template>
    <van-cell
        title="昵称"
        @click="toEdit('username', '昵称', user.username)"
        :value="user.username"
    />
    <van-cell title="账号" :value="user.userAccount" />
    <van-cell title="头像">
        <img :src="user.avatarUrl" style="height: 48px" />
    </van-cell>
    <van-cell
        title="性别"
        @click="toEdit('gender', '性别', user.gender == 1 ? '男' : '女')"
        :value="user.gender == 1 ? '男' : '女'"
    />
    <van-cell
        title="电话"
        @click="toEdit('phone', '电话', user.phone)"
        :value="user.phone"
    />
    <van-cell
        title="邮箱"
        @click="toEdit('email', '邮箱', user.email)"
        :value="user.email"
    />
    <van-cell title="星球编号" :value="user.planetCode" />
    <van-cell title="注册时间" :value="new Date(user.createTime).toString()" />
</template>
<style scoped lang="scss"></style>
